SQLSERVER数据库全局字符搜索 您所在的位置:网站首页 sql 全库搜索字段 SQLSERVER数据库全局字符搜索

SQLSERVER数据库全局字符搜索

2023-08-14 11:32| 来源: 网络整理| 查看: 265

SQLSERVER数据库全局字符搜索 前戏上代码说明:

前戏

为了提高整个数据库内容的搜索效率,我们要从一下几个方面去优化

1.用游标把数据库的表遍历出来,并一个个表,一个个列去匹配,在遍历表前,需要把无内容的表,或者数据量十分巨大但可能过滤的意义不大的表(某些软件爱写日志,往往几十万,上百万行数据,鼎捷MES半年试运行1.5亿行日志就问你怕不怕) 2. 变量列前,缩小遍历的类型,比如字符只搜索nvarchar或者varchar,如果找不到自行扩大数据类型. 3.希望在搜索的过程中可以一直监视进度,但不能影响搜索效率

上代码 DECLARE @sql VARCHAR(1024) DECLARE @table VARCHAR(64) DECLARE @column VARCHAR(64) DECLARE @value nvarchar(50) DECLARE @rows int DECLARE @count int DECLARE @index int set @value ='XX有限责任公司' set @count=0 if OBJECT_ID(N'tempdb..#t',N'U') is not null drop table #t CREATE TABLE #t (tablename VARCHAR(64),columnname VARCHAR(64),rows int) DECLARE TABLES scroll CURSOR FOR select a.name 表名,b.name 列名,ROW_NUMBER() over(order by a.name,b.name) 序号,c.rows from sysobjects a inner join syscolumns b on a.id=b.id inner join systypes lx on b.xusertype=lx.xusertype inner join (select id,max(rows) rows from sysindexes group by id) c on a.id=c.id where a.xtype='U' and c.rows>0 and c.rows


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有